package com.czl.module_service.fragment.assetUse

import com.alibaba.android.arouter.facade.annotation.Route
import com.czl.base.base.BaseFragment
import com.czl.base.config.AppConstants
import com.czl.base.data.bean.tengyun.SortBean
import com.czl.base.databinding.CommonEmptyLayoutBinding
import com.czl.module_service.BR
import com.czl.module_service.R
import com.czl.module_service.adapter.asset.PurchaseSortListAdapter
import com.czl.module_service.databinding.FragmentPurchaseSortListBinding
import com.czl.module_service.viewmodel.assetUse.PurchaseSortListViewModel

@Route(path = AppConstants.Router.Service.F_SERVICE_PURCHASE_SORT_LIST)
class PurchaseSortListFragment :
    BaseFragment<FragmentPurchaseSortListBinding, PurchaseSortListViewModel>() {

    private val mAdapter: PurchaseSortListAdapter by lazy {
        PurchaseSortListAdapter(this).apply {

        }
    }

    override fun initContentView(): Int {
        return R.layout.fragment_purchase_sort_list
    }

    override fun initVariableId(): Int {
        return BR.viewModel
    }

    override fun initData() {
        super.initData()
        viewModel.tvTitle.set("采购单物品")
        viewModel.purchaseId =
            arguments?.getSerializable(AppConstants.BundleKey.PURCHASE_CARD_KEY) as Int?
        initAdapter()
        reload()
    }


    private fun initAdapter() {
        binding.ryCommon.run {
            adapter = mAdapter
        }
    }

    override fun initViewObservable() {
        viewModel.uc.loadCompleteEvent.observe(this,{
                data ->
            showSuccessStatePage()
            mAdapter.setList(data as MutableList<SortBean>?)
            if (data.isEmpty()) {
                mAdapter.setEmptyView(CommonEmptyLayoutBinding.inflate(layoutInflater).root)
            }
        })
    }

    override fun reload() {
        super.reload()
        viewModel.getPurchaseStorageSortList(purchaseId = viewModel.purchaseId)
//        binding.ryCommon.autoRefresh()
    }

}